home *** CD-ROM | disk | FTP | other *** search
/ The PC-SIG Library 10 / The PC-Sig Library - Shareware for the IBM PC and Compatibles (PC-SIG)(Tenth Edition Disks 1-2804)(1991).iso / PC_SIGCD / 22 / 4 / DISK2247.ZIP / CBASE101.ZIP / CBASE.ZIP / CBSYNC.C < prev    next >
Text File  |  1990-06-21  |  2KB  |  80 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)cbsync.c    1.4 - 90/06/20" */
  5.  
  6. /* ansi headers */
  7. #include <errno.h>
  8.  
  9. /* library headers */
  10. #include <btree.h>
  11. #include <lseq.h>
  12.  
  13. /* local headers */
  14. #include "cbase_.h"
  15.  
  16. /*man---------------------------------------------------------------------------
  17. NAME
  18.      cbsync - synchronize cbase
  19.  
  20. SYNOPSIS
  21.      #include <cbase.h>
  22.  
  23.      int cbsync(cbp)
  24.      cbase_t *cbp;
  25.  
  26. DESCRIPTION
  27.      The cbsync function causes any buffered data for the named cbase
  28.      to be written out, both for the record and the key files.  The
  29.      cbase remains open and the buffer contents remain intact.
  30.  
  31.      cbsync will fail if one or more of the following is true:
  32.  
  33.      [EINVAL]       cbp is not a valid cbase pointer.
  34.      [EINVAL]       cbp is not open.
  35.  
  36. SEE ALSO
  37.      cbclose, cblock.
  38.  
  39. DIAGNOSTICS
  40.      Upon successful completion, a value of 0 is returned.  Otherwise,
  41.      a value of -1 is returned, and errno set to indicate the error.
  42.  
  43. ------------------------------------------------------------------------------*/
  44. int cbsync(cbp)
  45. cbase_t *cbp;
  46. {
  47.     int i = 0;
  48.  
  49.     /* validate input parameters */
  50.     if (!cb_valid(cbp)) {
  51.         errno = EINVAL;
  52.         return -1;
  53.     }
  54.  
  55.     /* check if not open */
  56.     if (!(cbp->flags & CBOPEN)) {
  57.         errno = CBENOPEN;
  58.         return -1;
  59.     }
  60.  
  61.     /* synchronize record file with buffers */
  62.     if (lssync(cbp->lsp) == -1) {
  63.         CBEPRINT;
  64.         return -1;
  65.     }
  66.  
  67.     /* synchronize key files with buffers */
  68.     for (i = 0; i < cbp->fldc; ++i) {
  69.         if (cbp->fldv[i].flags & CB_FKEY) {
  70.             if (btsync(cbp->btpv[i]) == -1) {
  71.                 CBEPRINT;
  72.                 return -1;
  73.             }
  74.         }
  75.     }
  76.  
  77.     errno = 0;
  78.     return 0;
  79. }
  80.